POV-Ray : Newsgroups : povray.general : cos(pi*3/2) results -0.000 : Re: cos(pi*3/2) results -0.000 Server Time
4 Aug 2024 22:15:08 EDT (-0400)
  Re: cos(pi*3/2) results -0.000  
From: Jellby
Date: 24 Jan 2003 15:43:44
Message: <3e31a57f@news.povray.org>
Entre otras cosas, Jano tuvo a bien escribir:

> If i do (i.e.) y= cos(x) where 0 < x < 2*pi and i'm testing the following:
>    #if(y < 0)
>       //block1...
>    #else //block2...
> 
> the result when x= pi*3/2 is block1! And taking a look at its value, is
> -0.00000 and is taken as negative number. By now i correct it simplyly
> checking such y value:  #macro correct(num)(num<0?:num=0?0:num:num) #end
> 
> Can someone confirm if this is a bug? Thanks

What would you expect?

cos(0) = 1
cos(pi*1/2) = 0
cos(pi) = -1
cos(pi*3/2) = 0

Unfortunately, POV-Ray is not perfect and there are (as in most computer 
programs) floatin point inaccuracies and rounding errors. That means the 
result is not *exactly* 0, but slightly lower, and you see -0.000. This is 
normal and expected behaviour, if you are testing against 0 you should in 
turn test that abs(y) < tiny_number.

-- 

Linux User #289967 (counter.li.org)
PGP Pub Key ID: 0x01A95F99 (pgp.escomplinux.org)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.